package com.pzhyd.sc.struts.action;

import java.io.IOException;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.pzhyd.sc.biz.inter.IvotedInfoBiz;
import com.pzhyd.sc.entity.Votedinfo;
import com.pzhyd.sc.util.DateUtil;
import com.pzhyd.sc.util.StringUtil;

/**
 * 
 * @author 李刚
 * @description 评选人信息 控制层
 * @date 2012.07.14
 */
public class VotedInfoAction extends DispatchAction {
	private IvotedInfoBiz ivotedInfoBiz;
	
	/**
	 * 查询投票无线平台列表
	 */
	public ActionForward listVotedInfo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws IOException  {
			request.setAttribute("listVotedInfo",this.ivotedInfoBiz.getVotedInfoList(null));
			return mapping.findForward("listVotedInfo");
	}
	/**
	 * 查询投票无线平台详细信息
	 */
	public ActionForward findVotedInfo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws IOException  {
		//记录访问量
		Votedinfo votedInfo=new Votedinfo(); 
		votedInfo.setViClicks(Integer.valueOf(request.getParameter("viClicks")));
		votedInfo.setViId(Integer.valueOf(request.getParameter("viId")));
		Integer rtnValue=this.ivotedInfoBiz.updateVotedInfo(votedInfo);
		if(rtnValue==1){
			//查询评选人信息Bean
			request.setAttribute("votedInfo",this.ivotedInfoBiz.getVotedInfo(Integer.valueOf(request.getParameter("viId"))));
			return mapping.findForward("findVotedInfo");
		}else{
			response.getWriter().write("<div align='center' style='font-size:20px;color:red;'>系统错误：请重新操作！</div>");
			return null;
		}
	}
	/**
	 * 记录投票量
	 */
	public ActionForward tracesVotedInfo(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws IOException  {
		String voAccount=request.getParameter("voAccount");
		String voTime=DateUtil.toFormatString(new Date(), "yyyyMMdd");
		String viId=request.getParameter("viId");		
		//手机IP
        String voIpaddr =StringUtil.isEmpty(request.getHeader("X-Forward-For"))?"":request.getHeader("X-Forward-For");
        //操作类型(1列表，2详细)
        String operatType=request.getParameter("operatType");	
        Integer rtnValue=this.ivotedInfoBiz.updateVotedInfo(voAccount, viId, voIpaddr);
        if(rtnValue==1 || rtnValue==-1){
        	if(rtnValue==-1){
        		request.setAttribute("warmsg","今天您已经投过票了，请明天再来投吧，谢谢！");
        	}
        	if("1".equals(operatType)){
        		request.setAttribute("listVotedInfo",this.ivotedInfoBiz.getVotedInfoList(null));
    			return mapping.findForward("listVotedInfo");
        	}else{
        		//查询评选人信息Bean
				request.setAttribute("votedInfo", this.ivotedInfoBiz.getVotedInfo(Integer.valueOf(request.getParameter("viId"))));
				return mapping.findForward("findVotedInfo");
        	}
		}else{
			response.getWriter().write("<div align='center' style='font-size:20px;color:red;'>系统错误：请重新操作！</div>");
			return null;
		}
	}
    /**
     * 以下是get，set方法
     */
	public IvotedInfoBiz getIvotedInfoBiz() {
		return ivotedInfoBiz;
	}

	public void setIvotedInfoBiz(IvotedInfoBiz ivotedInfoBiz) {
		this.ivotedInfoBiz = ivotedInfoBiz;
	}
}
